package cn.iocoder.yudao.module.promotion.groupon.controller.admin;

import cn.iocoder.yudao.framework.business.basic.controller.*;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.promotion.groupon.pojo.dto.AdminGrouponPackageGiftAddDTO;
import cn.iocoder.yudao.module.promotion.groupon.pojo.dto.AdminGrouponPackageGiftRemoveDTO;
import cn.iocoder.yudao.module.promotion.groupon.pojo.dto.AdminGrouponPackageQueryDTO;
import cn.iocoder.yudao.module.promotion.groupon.pojo.dto.AdminGrouponPackageSaveDTO;
import cn.iocoder.yudao.module.promotion.groupon.pojo.vo.AdminGrouponPackageVO;
import cn.iocoder.yudao.module.promotion.groupon.service.admin.AdminGrouponPackageService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

@Tag(name = "管理后台 - 团购套餐")
@RestController
@RequestMapping("/promotion/groupon-package")
@Validated
public class GrouponPackageController implements CreateController<AdminGrouponPackageSaveDTO>, UpdateController<AdminGrouponPackageSaveDTO>, DeleteController<Long>, DetailController<AdminGrouponPackageVO, Long>, PageController<AdminGrouponPackageVO, AdminGrouponPackageQueryDTO> {

    @Resource
    private AdminGrouponPackageService adminGrouponPackageService;

    @PreAuthorize("@ss.hasRole('shop_admin')")
    @Override
    public CommonResult<Long> create(AdminGrouponPackageSaveDTO param) {
        return success(adminGrouponPackageService.create(param));
    }

    @PreAuthorize("@ss.hasAnyRoles('shop_admin','super_admin', 'platform_admin', 'tenant_admin')")
    @Override
    public CommonResult<Boolean> update(AdminGrouponPackageSaveDTO param) {
        return success(adminGrouponPackageService.update(param));
    }

    @PreAuthorize("@ss.hasRole('shop_admin')")
    @Override
    public CommonResult<Boolean> delete(Long id) {
        return success(adminGrouponPackageService.delete(id));
    }

    @PreAuthorize("@ss.hasPermission('promotion:groupon:package')")
    @Override
    public CommonResult<AdminGrouponPackageVO> getDetail(Long id) {
        return success(adminGrouponPackageService.getDetail(id));
    }

    @PreAuthorize("@ss.hasPermission('promotion:groupon:package')")
    @Override
    public CommonResult<PageResult<AdminGrouponPackageVO>> getPage(Integer pageNo, Integer pageSize, AdminGrouponPackageQueryDTO param) {
        return success(adminGrouponPackageService.getPage(pageNo, pageSize, param));
    }

    @PreAuthorize("@ss.hasAnyRoles('shop_admin')")
    @Operation(summary = "添加赠品")
    @PostMapping("/add-gifts")
    public CommonResult<Boolean> addGifts(@Validated @RequestBody AdminGrouponPackageGiftAddDTO param) {
        return success(adminGrouponPackageService.addGifts(param));
    }

    @PreAuthorize("@ss.hasAnyRoles('shop_admin')")
    @Operation(summary = "移除赠品")
    @PostMapping("/remove-gift")
    public CommonResult<Boolean> removeGift(@Validated @RequestBody AdminGrouponPackageGiftRemoveDTO param) {
        return success(adminGrouponPackageService.removeGift(param));
    }

}
